<?php
namespace app\admin\controller;
use think\facade\Db;
class Notice extends Adm
{
	use \app\admin\traits\Curd;
    public function index()
    {
    	return $this->fetch();
    }
    /**
     * [_add 扩展]
     * 
     */
    protected function _add()
    {
    }
    //获取所有分类
    public function all()
    {
    	$data = ($this->_model)::select()->toArray();
    	$data = $this->arrtotreelist($data,'parent_id');
    	$count = null;
    	$this->assign(get_defined_vars());
    	$this->code = 0;
    	return $this->fetch();
    }
    public function data()
    {
        header('Content-Type:application/json;charset:utf-8');
        echo '{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"code":0,"msg":null,"count":14,"data":[{"createTime":"2021-03-14 00:10:41","createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"id":"1370769290961092608","title":"公告测试","content":"公告测试","sender":"1309861917694623744","senderName":"管理","accept":null,"acceptName":null,"type":"public"},{"createTime":"2021-03-14 00:10:55","createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"id":"1370769348204953600","title":"私信测试","content":"私信测试","sender":"1309861917694623744","senderName":"管理","accept":"1310409555649232897","acceptName":"如花","type":"private"},{"createTime":"2021-03-14 00:21:22","createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"id":"1370771980034244608","title":"公告测试","content":"公告测试","sender":"1309861917694623744","senderName":"管理","accept":null,"acceptName":null,"type":"public"},{"createTime":"2021-03-14 00:21:31","createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"id":"1370772014771470336","title":"公告测试","content":"公告测试","sender":"1309861917694623744","senderName":"管理","accept":null,"acceptName":null,"type":"public"},{"createTime":"2021-03-14 00:21:39","createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"id":"1370772050439831552","title":"公告测试","content":"公告测试","sender":"1309861917694623744","senderName":"管理","accept":null,"acceptName":null,"type":"public"},{"createTime":"2021-03-14 00:21:48","createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"id":"1370772089446858752","title":"私信测试","content":"私信测试","sender":"1309861917694623744","senderName":"管理","accept":"1310409555649232897","acceptName":"如花","type":"private"},{"createTime":"2021-03-14 00:22:01","createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"id":"1370772143918284800","title":"私信测试","content":"私信测试","sender":"1309861917694623744","senderName":"管理","accept":"1310409555649232897","acceptName":"如花","type":"private"},{"createTime":"2021-03-14 00:22:54","createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"id":"1370772363838226432","title":"私信测试","content":"私信测试","sender":"1309861917694623744","senderName":"管理","accept":"1349021166525743105","acceptName":"夏娜","type":"private"},{"createTime":"2021-03-14 00:23:18","createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"id":"1370772466212798464","title":"私信测试","content":"私信测试","sender":"1309861917694623744","senderName":"管理","accept":"1349021166525743105","acceptName":"夏娜","type":"private"},{"createTime":"2021-03-14 13:32:33","createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"id":"1370971086266564608","title":"私信测试","content":"私信测试","sender":"1309861917694623744","senderName":"管理","accept":"1309861917694623744","acceptName":"管理","type":"private"}]}';
    }
    public function loginLog()
    {
        header('Content-Type:application/json;charset:utf-8');
        echo '{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"code":0,"msg":null,"count":443,"data":[{"id":"1379263467143299072","title":"登录","description":"登录成功","businessType":"OTHER","requestMethod":"POST","method":"/login","operateUrl":"/login","operateAddress":"127.0.0.1","requestParam":null,"requestBody":null,"responseBody":null,"success":true,"loggingType":"LOGIN","errorMsg":null,"systemOs":"Windows","createTime":"2021-04-06 10:43:31","operateName":"admin","map":{},"browser":"谷歌浏览器"},{"id":"1379261535582420992","title":"登录","description":"登录成功","businessType":"OTHER","requestMethod":"POST","method":"/login","operateUrl":"/login","operateAddress":"127.0.0.1","requestParam":null,"requestBody":null,"responseBody":null,"success":true,"loggingType":"LOGIN","errorMsg":null,"systemOs":"Windows","createTime":"2021-04-06 10:35:50","operateName":"admin","map":{},"browser":"谷歌浏览器"},{"id":"1379256202201923584","title":"登录","description":"登录成功","businessType":"OTHER","requestMethod":"POST","method":"/login","operateUrl":"/login","operateAddress":"127.0.0.1","requestParam":null,"requestBody":null,"responseBody":null,"success":true,"loggingType":"LOGIN","errorMsg":null,"systemOs":"Windows","createTime":"2021-04-06 10:14:39","operateName":"admin","map":{},"browser":"谷歌浏览器"},{"id":"1379253026635644928","title":"登录","description":"登录成功","businessType":"OTHER","requestMethod":"POST","method":"/login","operateUrl":"/login","operateAddress":"127.0.0.1","requestParam":null,"requestBody":null,"responseBody":null,"success":true,"loggingType":"LOGIN","errorMsg":null,"systemOs":"Windows","createTime":"2021-04-06 10:02:01","operateName":"admin","map":{},"browser":"谷歌浏览器"},{"id":"1379252622208270336","title":"登录","description":"登录成功","businessType":"OTHER","requestMethod":"POST","method":"/login","operateUrl":"/login","operateAddress":"127.0.0.1","requestParam":null,"requestBody":null,"responseBody":null,"success":true,"loggingType":"LOGIN","errorMsg":null,"systemOs":"Windows","createTime":"2021-04-06 10:00:25","operateName":"admin","map":{},"browser":"谷歌浏览器"},{"id":"1379248740040179712","title":"登录","description":"登录成功","businessType":"OTHER","requestMethod":"POST","method":"/login","operateUrl":"/login","operateAddress":"127.0.0.1","requestParam":null,"requestBody":null,"responseBody":null,"success":true,"loggingType":"LOGIN","errorMsg":null,"systemOs":"Windows","createTime":"2021-04-06 09:44:59","operateName":"admin","map":{},"browser":"谷歌浏览器"},{"id":"1379246086652166144","title":"登录","description":"登录成功","businessType":"OTHER","requestMethod":"POST","method":"/login","operateUrl":"/login","operateAddress":"127.0.0.1","requestParam":null,"requestBody":null,"responseBody":null,"success":true,"loggingType":"LOGIN","errorMsg":null,"systemOs":"Windows","createTime":"2021-04-06 09:34:27","operateName":"admin","map":{},"browser":"火狐浏览器"},{"id":"1379244851572244480","title":"登录","description":"登录成功","businessType":"OTHER","requestMethod":"POST","method":"/login","operateUrl":"/login","operateAddress":"127.0.0.1","requestParam":null,"requestBody":null,"responseBody":null,"success":true,"loggingType":"LOGIN","errorMsg":null,"systemOs":"Windows","createTime":"2021-04-06 09:29:32","operateName":"admin","map":{},"browser":"谷歌浏览器"},{"id":"1379244826490306560","title":"登录","description":"登录成功","businessType":"OTHER","requestMethod":"POST","method":"/login","operateUrl":"/login","operateAddress":"127.0.0.1","requestParam":null,"requestBody":null,"responseBody":null,"success":true,"loggingType":"LOGIN","errorMsg":null,"systemOs":"Windows","createTime":"2021-04-06 09:29:26","operateName":"admin","map":{},"browser":"谷歌浏览器"},{"id":"1379243260601434112","title":"登录","description":"登录成功","businessType":"OTHER","requestMethod":"POST","method":"/login","operateUrl":"/login","operateAddress":"127.0.0.1","requestParam":null,"requestBody":null,"responseBody":null,"success":true,"loggingType":"LOGIN","errorMsg":null,"systemOs":"Mac","createTime":"2021-04-06 09:23:13","operateName":"admin","map":{},"browser":"谷歌浏览器"}]}';
    }
    private function listtotreearr(
        $lists,
        $parent_field='parent_id',
        $parent_id=0,
        $son_field='children'
    )
    {
        $list = [];
        $rows = $lists;
        foreach($rows as $k=>$v)
        {
            $data = $v;
            $data['children'] = [];
            if($v['parent_id']==$parent_id)
            {
                unset($lists[$k]);
                $sons = $this->arrtotreelist($lists,$parent_field,$v['id']);
                foreach($sons as $i=>$item){
                    array_push($data['children'], $item);
                }
                array_push($list, $data);
            }
        }
        return $list;
    }
    public function selectParent()
    {
        header('Content-Type:application/json; charset=utf-8');
        $data = Db::name('cate')->select();
        $data[] = [
            "id"=>"0",
            "name"=>"顶级分类",
            "parent_id"=>"-1",
            "sort"=>null
        ];
        $response = [
            'status'=>[
                'code'=>'200',
                'msessage'=>''
            ],
            'data'=>$data
        ];
        return json($response);
    }
    private function arrtotreelist($lists,$parent_field='parent_id',$parent_id=0)
    {
    	$list = [];
    	$rows = $lists;
    	foreach($rows as $k=>$v)
    	{
    		if($v['parent_id']==$parent_id)
    		{
    			array_push($list, $v);
    			unset($lists[$k]);
    			$sons = $this->arrtotreelist($lists,$parent_field,$v['id']);
    			foreach($sons as $i=>$item){
    				array_push($list, $item);
    			}
    		}
    	}
    	return $list;
    }
}
